package cn.gson.fengboot.model.service;


import cn.gson.fengboot.model.dao.QtypeDao;
import cn.gson.fengboot.model.mapper.QguigeMapper;
import cn.gson.fengboot.model.mapper.QtypeEntityMapper;
import cn.gson.fengboot.model.pojos.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

@Service
@Transactional(rollbackFor = Exception.class)
public class QleibiecxService {

    @Autowired
    QguigeMapper qguigeMapper;
    @Autowired
    QtypeEntityMapper qtypeEntityMapper;
    @Autowired
    QtypeDao qtypeDao;



    //查询一级
    public List<Qleibievo> parentType() {
        return qguigeMapper.allFunctionType(null );
    }

    //查询子级
    public List<Qleibievo> functionTypes(Qleibievo parentType) {
        //根据父级查询子级
        List<Qleibievo> functionTypes = qguigeMapper.allFunctionType(parentType.getTypeid());
        //循环当前级别
        for (Qleibievo functionType : functionTypes) {
            //递归调用查询子级的方法，查询该级别下的子级，并赋值到该级别下的子级集合
            functionType.setFunctionTypes(this.functionTypes(functionType));
        }
        return functionTypes;
    }

    //查询所有类别
    public List<Qleibievo> allFunctionType() {
        //查询一级
        List<Qleibievo> parentType = this.parentType();
        //查询一级下的二级，在这个方法里，会递归查询子级
        for (Qleibievo functionType : parentType) {
            functionType.setFunctionTypes(this.functionTypes(functionType));
        }
        return parentType;
    }


    public List<QtypeEntity> leibielist(){
        return qtypeEntityMapper.leibielist();
    }

    //xz
    public  void addleibie(QtypeEntity qtypeEntity){
        //新增规格名称  取规格名称新增之后的规格对象
        QtypeEntity save = qtypeDao.save(qtypeEntity);
    }
}
